﻿using System.Collections;
using System.Collections.Generic;
using MWS.Processing.Interfaces;

namespace MWS.Processing.Queues
{
    public class MemoryQueue<T> : IQueue<T>
    {
        private readonly Queue queue = new Queue();

        public void Clear()
        {
            queue.Clear();
        }

        public void Enqueue(T item)
        {
            queue.Enqueue(item);
        }

        public IList<T> Dequeue(int maxItems)
        {
            var items = new List<T>();
            for (var i = 0; i < maxItems; i++)
            {
                lock (queue)
                    if (queue.Count > 0)
                        items.Add((T) queue.Dequeue());
            }
            return items;
        }

        public T Peek()
        {
            return (T) queue.Peek();
        }

        public bool Contains(T item)
        {
            return queue.Contains(item);
        }
    }
}